import requests


class IhrmApi:
    @classmethod
    def ihrm_login_api(cls, login_body):
        login_url = "http://ihrm2-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_resp = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_resp

    #添加员工接口
    @classmethod
    def add_api(cls,token,add_body):
        add_url = "http://ihrm2-test.itheima.net/api/sys/user"
        add_header = {"Content-Type": "application/json", "Authorization": token}
        add_resp = requests.post(url=add_url, headers=add_header, json=add_body)
        return add_resp
    #查询员工接口
    @classmethod
    def find_api(cls,emp_id,token):
        find_url = "http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        find_header = {"Authorization":token}
        find_resp = requests.get(url=find_url, headers=find_header)
        return find_resp
    #修改员工接口
    @classmethod
    def update_api(cls,emp_id,token,update_body):
        update_url = "http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        update_header = {"Content-Type": "application/json", "Authorization": token}
        update_resp = requests.put(url=update_url, headers=update_header, json=update_body)
        return update_resp
    #删除员工接口
    @classmethod
    def delete_api(cls,emp_id,token):
        delete_url = "http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        delete_header = {"Authorization": token}
        delete_resp = requests.delete(url=delete_url, headers=delete_header)
        return delete_resp


if __name__ == '__main__':
    token="80fee80c-9b78-4596-9715-22f497c2ee0c"
    add_body={
    "username": "小猪佩奇",
    "mobile": "15916633145",
    "workNumber": "22"
}
    resp=IhrmApi.add_api(token,add_body)
    print("resp=",resp.json())


